package ui;

import game.Game;

import java.io.File;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.UnicodeFont;
import org.newdawn.slick.font.effects.ColorEffect;
import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.util.Log;

import utility.Util;

public class GameStateSwitcher extends StateBasedGame {
	private boolean didSucceed;
	private boolean isLevelLoaded = false;
	private Game gameState;
	private GameMenuState gameMenuState;
	
	public GameStateSwitcher(String name) {
		super(name);
	}

	@Override
	public void initStatesList(GameContainer container) throws SlickException {
		gameState = new Game(Util.resources+"levels"+File.separator+"test.txt");
		gameMenuState = new GameMenuState();
		this.addState(gameMenuState);
		this.addState(gameState);
		this.addState(new GameOptionState());
		this.addState(new LoadingState());
		this.addState(new GameCompletionState());
	}
	
	public void loadLevel(String levelName, boolean forceLoad) throws SlickException {
		if ((!gameState.hasLoadedLevel() && !levelName.equals(gameState.getLevelName())) || forceLoad)
			gameState.loadLevel(getContainer(), levelName);
	}
	
	public void resetMenu(){
		gameMenuState.resetGameMenuState(getContainer());
	}
	
	public boolean isLevelLoaded() {
		return isLevelLoaded;
	}

	public void setIsLevelLoaded(boolean isLevelLoaded) {
		this.isLevelLoaded = isLevelLoaded;
	}
	
	public int getCurrentLevel() {
		return gameState.getLevelNumber();
	}

	public void setSuccess(boolean didSucceed) {
		this.didSucceed = didSucceed;
	}
	
	public boolean getSuccess(){
		return didSucceed;
	}

	public static final int GAME_STATE = 0;
	public static final int MENU_STATE = 1;
	public static final int OPTION_STATE = 2;
	public static final int LOADING_STATE = 3;
	public static final int COMPLETION_STATE = 4;
}
